//==========================================================================
// Copyright (c) 2000-2009,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CGRAFIXENGINE_H__
#define __CGRAFIXENGINE_H__

#include <engine.h>

#define _NO_CGRAFIXENGINE_CLASSOBJECT_
#include "_CGrafixEngine.h"

#define MAX_LAYER           3

#define DEFAULT_FONT_SIZE   20

class CGrafixLayer;

//
// x_new = xx * x + xy * y + x0;
// y_new = yx * x + yy * y + y0;
//
struct Matrix {
    Int32 xx; // xx component of the affine transformation
    Int32 yx; // yx component of the affine transformation
    Int32 xy; // xy component of the affine transformation
    Int32 yy; // yy component of the affine transformation
    Int32 x0; // X translation component of the affine transformation
    Int32 y0; // Y translation component of the affine transformation
};

extern Matrix g_transformMatrix[4];
extern Matrix g_RenderMatrix[4];

CarClass(CGrafixEngine)
{
public:
    CARAPI constructor();

    ~CGrafixEngine();

    Void *operator new(size_t size, void * pv) { return pv; }

    Void *operator new(size_t size) { return malloc(size); }

    Void operator delete(void * pv) { free(pv); }

public:
    CARAPI AcquireGrafixLayer(
        /* [in] */ Int32 layerId,
        /* [out] */ IGrafixLayer ** ppLayer);

    CARAPI CreateGrafixObject(
        /* [in] */ WString name,
        /* [in] */ const struct GrafixObjectParams & params,
        /* [out] */ IGrafixObject ** ppGrafixObject);

    CARAPI CreateGrafixSurface(
        /* [in] */ const struct GrafixSurfaceParams & params,
        /* [out] */ IGrafixSurface ** ppGrafixSurface);

    CARAPI BroadcastGrafixEvent(
        /* [in] */ const struct GrafixObjectEvent & event);

    CARAPI GetAllGrafixObjects(
        /* [in] */ Int32 appletId,
        /* [out] */ IObjectEnumerator ** ppGrafixObjects);

    CARAPI AcquireGrafixEventBuffer(
        /* [in] */ Int32 contextId,
        /* [out] */ IGrafixEventBuffer ** ppEventBuffer);

    CARAPI Render();

    CARAPI RenderRegion(
        /* [in] */ Int32 x,
        /* [in] */ Int32 y,
        /* [in] */ Int32 width,
        /* [in] */ Int32 height);

    CARAPI SetScreenScreenOrientation(
        /* [in] */ ScreenOrientation orientation);

    CARAPI GetScreenScreenOrientation(
        /* [out] */ ScreenOrientation * pOrientation);

public:
    Void Render(
        /* [in] */ CGrafixSurface * pSurface);

    ECode EnableStack(
        /* [in] */ Int32 width,
        /* [in] */ Int32 height);

    ECode DisableStack();

public:
    Int32 m_elementCount;
    CGrafixLayer* m_collection[MAX_LAYER];

    CGrafixEventBuffer m_eventBufferHeader;

    GrafixObjectStack* m_stack;
    Int32 m_stackRef;

    CGrafixLayer* m_currentLayer;

    RectangleLink m_layerTransparentRect;
    RectangleLink m_renderRect;

    ScreenOrientation m_orientation;
};

#endif // __CGRAFIXENGINE_H__
